# moore's voting algorithm

import sys

class Solution(object):
    def majorityElement(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        cnt1 = 0
        cnt2 = 0
        num1 = sys.maxsize
        num2 = sys.maxsize
        for num in nums:
            if num==num1:
                cnt1+=1
            elif num==num2:
                cnt2+=1
            elif cnt1==0:
                cnt1, num1 = 1, num
            elif cnt2==0:
                cnt2, num2 = 1, num
            else:
                cnt1-=1
                cnt2-=1
        return [n for n in (num1, num2) if nums.count(n) > len(nums)//3]